package com.demo.concurrent;

/**
 * @author shenguangyang
 */
public class VolatileE02 {
    volatile int i;

    public void addI(){
        i++;
    }

    public static void main(String[] args) throws InterruptedException {
        final  VolatileE02 test01 = new VolatileE02();
        for (int n = 0; n < 1000; n++) {
            new Thread(() -> {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                test01.addI();
            }).start();
        }

        // 等待10秒，保证上面程序执行完成
        Thread.sleep(10000);

        System.out.println(test01.i);
    }
}
